<?php
/* Author: tbloc@cantho.gov.vn */
/* Created Date : 17-07-2014 10:10:51 */
class M_Loai_hang{  
//Properties
private $LH_ID;
private $LH_TENLOAI;
//properties set get 
public function setLH_ID($LH_ID) 
{
	$this->LH_ID = $LH_ID;
}
public function getLH_ID()
{
	return $this->LH_ID;
}	        
public function setLH_TENLOAI($LH_TENLOAI) 
{
	$this->LH_TENLOAI = $LH_TENLOAI;
}
public function getLH_TENLOAI()
{
	return $this->LH_TENLOAI;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `loai_hang`(                        
			`LH_ID`, 
				`LH_TENLOAI` 
		)
	VALUES(
    		:LH_ID, 
	    		:LH_TENLOAI 
	    );";
	$parameters = array(
			":LH_ID", 
				":LH_TENLOAI" 
		);
    $values = array(  
            	$this->getLH_ID(), 
	            	$this->getLH_TENLOAI()
	    );
    $types = array(
   
                                    PDO::PARAM_INT,
                                                        PDO::PARAM_STR
                       );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setLH_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "update `loai_hang`
	                set `is_active`=0
	                where `LH_ID` = :LH_ID;";
	        $parameters = array(":LH_ID");
	        $values = array($this->getLH_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `loai_hang` SET 
			`LH_ID`=:LH_ID,
				`LH_TENLOAI`=:LH_TENLOAI
			WHERE `LH_ID` = :LH_ID;";
	            $parameters = array(
	        	":LH_ID",
		        	":LH_TENLOAI"
		        );	
	$values = array(  
	        	$this->getLH_ID(),
        	                $this->getLH_TENLOAI()      
        	);
    $types = array(
                                    PDO::PARAM_INT,
                                                       PDO::PARAM_STR
                       );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`LH_ID`,
				`LH_TENLOAI`
			FROM `loai_hang` WHERE `LH_ID` = :LH_ID and `is_active`=1;";
	$parameters = array(":LH_ID");
	$values = array($this->getLH_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setLH_ID($row->LH_ID);
		$this->setLH_TENLOAI($row->LH_TENLOAI);
	}
	return $this;
		}
	}
	
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`LH_ID`,
				`LH_TENLOAI`
			FROM `loai_hang` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new loai_hang();
    	 $obj->setLH_ID($row->LH_ID);
		 $obj->setLH_TENLOAI($row->LH_TENLOAI);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

